package com.wondersgroup.aspectjtest;

import android.util.Log;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by Administrator on 2016/12/25.
 */

/**
 *切面
 * 你想要切的蛋糕
 */
@Aspect
public class BehaviorAspect {
    final String TAG = "hss";
    SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
/**
 * 如何切蛋糕，切成什么样的形状
 * 切点
 */
    @Pointcut("execution(@com.wondersgroup.aspectjtest.BehaviorTrace  * *(..))")
    public void annoBehavior(){

    }

    /**
     * 切面
     * 蛋糕按照切点切下来之后   怎么吃
     * @param point
     * @return
     */
    @Around("annoBehavior()")
    public  Object dealPoint(ProceedingJoinPoint point) throws Throwable {
        //方法执行前
        MethodSignature methodSignature = (MethodSignature) point.getSignature();
        BehaviorTrace behaviorTrace = methodSignature.getMethod().getAnnotation(BehaviorTrace.class);
        String value = behaviorTrace.value();
        int type=behaviorTrace.type();
        Log.i(TAG,value+"使用时间：   "+simpleDateFormat.format(new Date()));
        long beagin=System.currentTimeMillis();
        Object object = null;
        object = point.proceed();

        //方法执行完成
        Log.i(TAG,"消耗时间：  "+(System.currentTimeMillis()-beagin)+"ms");
        return  object;
    }
}
